package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.sl.au.entity.InventoryDull;
import com.sl.au.repository.InventoryDullRepository;
import com.sl.au.repository.QuoteDeviceRepository;
import com.sl.au.service.InventoryDullService;
@Service("InventoryDullService")
@Transactional
public class InventoryDullServiceImpl extends BaseServiceImpl implements InventoryDullService {

	@Autowired
	InventoryDullRepository inventoryDullRepository;
	@Autowired
	QuoteDeviceRepository quoteDeviceRepository;
	
	@Override
	public InventoryDullRepository getRepository() {
		return this.inventoryDullRepository;
	}
	@Override
	public QuoteDeviceRepository getDeviceRepository() {
		return this.quoteDeviceRepository;
	}

	@Override
	public List<InventoryDull> getInventoryDull(int start, int length, String key, String orderName, String dir) {
		Page<InventoryDull> pages = null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "createTime");
		if(StringUtils.hasText(key)){
			pages = inventoryDullRepository.findInventoryDull(key,pageable);
		}
		else 
			pages = inventoryDullRepository.findNoReplace(pageable);
		return pages.getContent();
	}

	@Override
	public List<InventoryDull> getInventoryDullBykey(int start, int length, String key, String orderName, String dir) {
		Page<InventoryDull> pages = null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "createTime");
		if(StringUtils.hasText(key)){
			pages = inventoryDullRepository.findInventoryDullBykey(key,pageable);
		}
		else 
			pages = inventoryDullRepository.findAll(pageable);
		return pages.getContent();
	}

}
